

#include "procedure.h"
#include "../basic/operator.h"


/*
// (add-constructor Circle make-circle (radius))
// define-function?
Cell* op_add_constructor(Scheme *sc) {
	Cell *className = first(sc->args);
	Cell* clazz = find_class_by_name(sc, className);
	Cell *constructorName = second(sc->args);
	Cell *constructorArgs = third(sc->args);
	Cell *constructor = cons(sc, constructorName, constructorArgs);
	method->_type = CONSTRUCTOR_TYPE;
	add_constructor_to_class(sc, clazz, constructor);
	return s_return_helper(sc, &g_true);
}

// (delete-constructor Circle make-circle)
// delete-function?
Cell* op_delete_constructor(Scheme *sc) {
	PRIVILEGE_CHECK(sc);
	Cell *className = first(sc->args);
	Cell *constructor = second(sc->args);
	delete_constructor_of_class(sc, constructor);
	return s_return_helper(sc, &g_true);
}
*/


Cell* make_procedure(Scheme *sc, const char *name, OperatorFunc f) {
	Cell* x = make_cell(sc, G_NIL, G_NIL);
	// (x)->_flag = T_ATOM;
	(x)->_type = PROCEDURE_TYPE;
	(x)->_name = name;
	(x)->_op = f;
	return (x);
}


// (procedure? x)
Cell* op_procp(Scheme *sc) {
	/*continuation should be procedure by the example
	 * (call-with-current-continuation procedure?) ==> #t
	 * in R^3 report sec. 6.9*/

	int istrue = type_of(sc, first(sc->args), PROCEDURE_TYPE);
	// int istrue = (is_proc(first(sc->args)) || is_closure(first(sc->args)) || is_continuation(first(sc->args)));
	sc->returnValue = (istrue) ? G_TRUE : G_FALSE;
	return pop_callstack(sc);
}


void init_procedure_operators(Scheme *sc) {
	;
}

